1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @defgroup ANativeWindow Native Window 19 * 20 * ANativeWindow represents the producer end of an image queue. 21 * It is the C counterpart of the android.view.Surface object in Java, 22 * and can be converted both ways. Depending on the consumer, images 23 * submitted to ANativeWindow can be shown on the display or sent to 24 * other consumers, such as video encoders. 25 * @{ 26 */ 27 28 /** 29 * @file native_window.h 30 * @brief API for accessing a native window. 31 */ 32 33 module android.ndk.native_window; 34 35 import arsd.jni; 36 import android.ndk; 37 38 extern (C): 39 nothrow: 40 @nogc: 41 42 /** 43 * Legacy window pixel format names, kept for backwards compatibility. 44 * New code and APIs should use AHARDWAREBUFFER_FORMAT_*. 45 */ 46 enum ANativeWindow_LegacyFormat 47 { 48 // NOTE: these values must match the values from graphics/common/x.x/types.hal 49 50 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ 51 WINDOW_FORMAT_RGBA_8888 = AHardwareBuffer_Format.AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, 52 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/ 53 WINDOW_FORMAT_RGBX_8888 = AHardwareBuffer_Format.AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM, 54 /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ 55 WINDOW_FORMAT_RGB_565 = AHardwareBuffer_Format.AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM 56 } 57 58 /** 59 * Transforms that can be applied to buffers as they are displayed to a window. 60 * 61 * Supported transforms are any combination of horizontal mirror, vertical 62 * mirror, and clockwise 90 degree rotation, in that order. Rotations of 180 63 * and 270 degrees are made up of those basic transforms. 64 */ 65 enum ANativeWindowTransform 66 { 67 ANATIVEWINDOW_TRANSFORM_IDENTITY = 0x00, 68 ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL = 0x01, 69 ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL = 0x02, 70 ANATIVEWINDOW_TRANSFORM_ROTATE_90 = 0x04, 71 72 ANATIVEWINDOW_TRANSFORM_ROTATE_180 = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL | ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL, 73 ANATIVEWINDOW_TRANSFORM_ROTATE_270 = ANATIVEWINDOW_TRANSFORM_ROTATE_180 | ANATIVEWINDOW_TRANSFORM_ROTATE_90 74 } 75 76 struct ANativeWindow; 77 /** 78 * Opaque type that provides access to a native window. 79 * 80 * A pointer can be obtained using {@link ANativeWindow_fromSurface()}. 81 */ 82 83 /** 84 * Struct that represents a windows buffer. 85 * 86 * A pointer can be obtained using {@link ANativeWindow_lock()}. 87 */ 88 struct ANativeWindow_Buffer 89 { 90 /// The number of pixels that are shown horizontally. 91 int width; 92 93 /// The number of pixels that are shown vertically. 94 int height; 95 96 /// The number of *pixels* that a line in the buffer takes in 97 /// memory. This may be >= width. 98 int stride; 99 100 /// The format of the buffer. One of AHardwareBuffer_Format. 101 int format; 102 103 /// The actual bits. 104 void* bits; 105 106 /// Do not touch. 107 uint[6] reserved; 108 } 109 110 /** 111 * Acquire a reference on the given {@link ANativeWindow} object. This prevents the object 112 * from being deleted until the reference is removed. 113 */ 114 void ANativeWindow_acquire (ANativeWindow* window); 115 116 /** 117 * Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}. 118 */ 119 void ANativeWindow_release (ANativeWindow* window); 120 121 /** 122 * Return the current width in pixels of the window surface. 123 * 124 * \return negative value on error. 125 */ 126 int ANativeWindow_getWidth (ANativeWindow* window); 127 128 /** 129 * Return the current height in pixels of the window surface. 130 * 131 * \return a negative value on error. 132 */ 133 int ANativeWindow_getHeight (ANativeWindow* window); 134 135 /** 136 * Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface. 137 * 138 * \return a negative value on error. 139 */ 140 int ANativeWindow_getFormat (ANativeWindow* window); 141 142 /** 143 * Change the format and size of the window buffers. 144 * 145 * The width and height control the number of pixels in the buffers, not the 146 * dimensions of the window on screen. If these are different than the 147 * window's physical size, then its buffer will be scaled to match that size 148 * when compositing it to the screen. The width and height must be either both zero 149 * or both non-zero. 150 * 151 * For all of these parameters, if 0 is supplied then the window's base 152 * value will come back in force. 153 * 154 * \param width width of the buffers in pixels. 155 * \param height height of the buffers in pixels. 156 * \param format one of the AHardwareBuffer_Format constants. 157 * \return 0 for success, or a negative value on error. 158 */ 159 int ANativeWindow_setBuffersGeometry ( 160 ANativeWindow* window, 161 int width, 162 int height, 163 int format); 164 165 /** 166 * Lock the window's next drawing surface for writing. 167 * inOutDirtyBounds is used as an in/out parameter, upon entering the 168 * function, it contains the dirty region, that is, the region the caller 169 * intends to redraw. When the function returns, inOutDirtyBounds is updated 170 * with the actual area the caller needs to redraw -- this region is often 171 * extended by {@link ANativeWindow_lock}. 172 * 173 * \return 0 for success, or a negative value on error. 174 */ 175 int ANativeWindow_lock ( 176 ANativeWindow* window, 177 ANativeWindow_Buffer* outBuffer, 178 ARect* inOutDirtyBounds); 179 180 /** 181 * Unlock the window's drawing surface after previously locking it, 182 * posting the new buffer to the display. 183 * 184 * \return 0 for success, or a negative value on error. 185 */ 186 int ANativeWindow_unlockAndPost (ANativeWindow* window); 187 188 /** 189 * Set a transform that will be applied to future buffers posted to the window. 190 * 191 * \param transform combination of {@link ANativeWindowTransform} flags 192 * \return 0 for success, or -EINVAL if \p transform is invalid 193 */ 194 int ANativeWindow_setBuffersTransform (ANativeWindow* window, int transform); 195 196 // __ANDROID_API__ >= 26 197 198 /** 199 * All buffers queued after this call will be associated with the dataSpace 200 * parameter specified. 201 * 202 * dataSpace specifies additional information about the buffer. 203 * For example, it can be used to convey the color space of the image data in 204 * the buffer, or it can be used to indicate that the buffers contain depth 205 * measurement data instead of color images. The default dataSpace is 0, 206 * ADATASPACE_UNKNOWN, unless it has been overridden by the producer. 207 * 208 * \param dataSpace data space of all buffers queued after this call. 209 * \return 0 for success, -EINVAL if window is invalid or the dataspace is not 210 * supported. 211 */ 212 int ANativeWindow_setBuffersDataSpace (ANativeWindow* window, int dataSpace); 213 214 /** 215 * Get the dataspace of the buffers in window. 216 * \return the dataspace of buffers in window, ADATASPACE_UNKNOWN is returned if 217 * dataspace is unknown, or -EINVAL if window is invalid. 218 */ 219 int ANativeWindow_getBuffersDataSpace (ANativeWindow* window); 220 221 // __ANDROID_API__ >= 28 222 223 // ANDROID_NATIVE_WINDOW_H 224 225 /** @} */